<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>
<style>
    .class-title {
        margin-top: 10px;
        margin-left: 10px;
        margin-right: 10px;
        font-size: 20px;
        font-weight: bold;
        color: #00BFFF;
    }

    .class-hr {
        margin-top: 5px;
        height: 1px;
        border: none;
        border-top: 1px solid #DCDCDC;
    }

    .class-seqno {
        margin-top: 3px;
        margin-left: 10px;
        margin-right: 25px;
        font-size: 10px;
        color: #808080;
        font-weight: bold;
        text-align: right;
    }

    .class-table {
        width: 100%;
        text-align: left;
        color: black;
        font-size: 13px;
        margin-left: 2%;
        width: 100%;
        table-layout: fixed;
    }

    .class-td {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .lw {
        background-color: #DCE9F2;
        border-top: 1px solid #CBD6DE;
        border-bottom: 1px solid #ADBECB;
        color: #467aa7;
        font-size: 12px;
        font-weight: bold;
    }

    .lw1 {
        background-color: #f0f5f5;
        border-top: 1px solid #CBD6DE;
        border-bottom: 1px solid #ADBECB;
        color: #467aa7;
        font-size: 12px;
    }

    /* .table {
            margin-bottom: 15px;
            width: 100%;
            border-collapse: collapse;
            font-size: 13px;
            margin-bottom: 15px;
            width: 100%;
            border-collapse: collapse;
        }

        .table td {
            height: 40px;
            text-align: left;
            border: 0px solid #CBD6DE;
            padding: 0;
            margin: 0;
        } */

    .aui-searchbar-input {
        width: 95% !important;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">

        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">客户</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请选择/扫描客户" id="customerCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectCustomer()"></i>
                </div>
            </li>
            <li class="aui-list-item" style="display: none;">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">发货单号</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描/输入发货单号" id="consignment" value=""
                            onclick="getIdSelector();">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">容器码</div>
                    <!-- <div class="aui-list-item-input"> -->
                        <input type="text" placeholder="请扫描 容器码/箱码" id="boxnum" value="" onclick="getIdSelector();"
                            onfocus="focusFn(this)">
                        <i class="aui-input-addon aui-iconfont aui-icon-scan "
                            style="padding-right:10px;font-size: 1.6rem" onclick="doScan();"></i>
                    <!-- </div> -->
                </div>
            </li>
            <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="tm">
                    </div>
                </div>
            </li>
            <li class="aui-list-item" style="display:none">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">条码ID</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="tmID">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">调入库位</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请选择/扫描调入库位" id="relWorkCellCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell('2')"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">调出库位</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请选择/扫描调出库位" id="workCellCode" value=""
                            onclick="getIdSelector();" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectWorkCell('1')"></i>
                </div>
            </li>
            <div style="background-color:white;width: 100%;margin-top:2%;margin-bottom:5px;">
                <table class="table" style='width:100%;' id="table">
                    <thead>
                        <tr
                            style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 8px;font-weight: bold;">
                            <td algin='center'>物料编码</td>
                            <td algin='center'>规格</td>
                            <td algin='center'>数量</td>
                        </tr>
                    </thead>
                    <tbody id="tbodyHtml">
                    </tbody>
                </table>
            </div>
            <div class="aui-list-item-inner">
                <div class="aui-list-item-label" style="margin-left:30%;width:100%">已扫描容器数：</div>
                <div class="aui-list-item-input" style="margin-left:5%">
                    <input type="text" id="num" value="" disabled="true" style='color:red' />
                </div>
            </div>

        </ul>
        <ul class="ui-selectee" id="tbodyHtmlS">

        </ul>
    </div>

    <div style="width:100%;margin-top:50%;"></div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()" id="submitButton">保存</div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var customerGid = ""; //客户GID
    var customerCode = ""; //客户编码
    var customerName = ""; //客户名称
    var workCellGid = ""; //调出库位GID
    var workCellCode = ""; //调出库位编码
    var workCellName = ""; //调出库位名称
    var relWorkCellGid = ""; //调入库位GID
    var relWorkCellCode = ""; //调入库位编码
    var relWorkCellName = ""; //调入库位名称
    var codesub; //菜单路由参数 子业务类型
    var title = ""; //菜单名

    var scanRule = ""; //条码解析规则
    var relworkcell; //菜单路由参数
    var originworkcell; //菜单路由参数
    var flag = true;

    var arrSave = [];//需要提交的物料信息
    var arrSaveContainer = '';//需要提交的容器/箱信息

    var num = 0;
    let tableStr = [];

    //初始化查询仓库下拉框
    apiready = function () {

        //菜单参数
        var query = api.pageParam.query;

        codesub = query.codesub;
        title = query.title;
        relworkcell = query.relworkcell
        originworkcell = query.originworkcell
        console.log("目：" + relworkcell);
        console.log("源：" + originworkcell);
        if (title != undefined && title != null && title != "") {
            document.getElementById("title").innerHTML = title;
        }
        $("#num").val(0);

        $("#customerCode").focus();
        idSelector = "customerCode";
        //查询条码解析规则
        initScanRule();
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //查询扫描规则
    function initScanRule() {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem("un");
        var url = serverUrl + "/app/getTmScanRule";
        var data = {
            values: {
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    scanRule = myobj.scanRule
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {

            //1：调出库位
            if (idSelector == 'workCellCode') {

                $("#workCellCode").val(ret);
                //查询调出库位
                getWorkCell(ret, idSelector, "1");

                //24：调入库位
            } else if (idSelector == 'relWorkCellCode') {

                $("#relWorkCellCode").val(ret);
                //查询调入库位
                getWorkCell(ret, idSelector, "2");

                //5：扫描容器条码
            } else if (idSelector == 'boxnum') {
                $("#boxnum").blur();
                $("#boxnum").val("");
                //扫描之后条码解析
                tmSplit(ret);
            } else if (idSelector == 'customerCode') {

                $("#customerCode").val(ret);
                //查询客户
                getCustomer(ret, idSelector);
            } else if (idSelector == 'consignment') {
                $("#consignment").val(ret);
            }
        });
    }

    //9；PDA自带扫描回车事件-客户
    $("#customerCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#customerCode").val(sm);
            getCustomer(sm, "customerCode");
        }
    });

    //7:库位扫描校验
    function getWorkCell(code, inputId, flag) {
        var un = localStorage.getItem("un");
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getWorkCell";
        var data = {
            values: {
                flag: "out_kj", //库内库间标识（out_kn库内  out_kj库间,in_rk入库出库）
                workCenterGid: "", //仓库GID
                workCellCode: code, //库位编码
                relWorkCellGid: "", //调入库位
                tm: "",
                workCellFlag: "", //原库位调入库位flag
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    //源库位
                    if (flag == "1") {

                        workCellGid = list[0].workCellGid;
                        workCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                        workCellName = list[0].workCellName;
                        document.getElementById(inputId).value = workCellCode;
                        $("#customerCode").focus();
                        idSelector = "customerCode";

                        //调入库位
                    } else if (flag == "2") {

                        relWorkCellGid = list[0].workCellGid;
                        relWorkCellCode = list[0].workCellCode + ":" + list[0].workCellName;
                        relWorkCellName = list[0].workCellName;
                        document.getElementById(inputId).value = relWorkCellCode;
                        $("#workCellCode").focus();
                        idSelector = "workCellCode";
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#" + inputId).focus();
                    $("#" + inputId).select();
                }
            }
        });
    }

    //8：选择库位
    function goSelectWorkCell(workCellFlag) {
        var tm = $("#tm").val();
        api.openWin({
            name: 'uwmSelectWorkCell',
            url: 'uwmSelectWorkCell.html',
            pageParam: {
                flag: "out_kj",
                name: "uwmInterBankTransferRqfh_zfzjcxcc",
                tm: tm,
                workCenterGid: "",
                relWorkCellGid: relWorkCellGid,
                workCellFlag: workCellFlag
            }
        });
    }

    //库位选择后回调函数
    function setWorkCell(id, code, name, workCellFlag) {

        //源库位
        if (workCellFlag == "1") {

            workCellGid = id;
            workCellCode = code;
            workCellName = name;
            document.getElementById('workCellCode').value = code + ":" + name;

            //调入库位
        } else if (workCellFlag == "2") {

            relWorkCellGid = id;
            relWorkCellCode = code;
            relWorkCellName = name;
            document.getElementById('relWorkCellCode').value = code + ":" + name;
            $("#workCellCode").focus();
            var e = "workCellCode";
            idSelector = e;
        }
    }

    //客户
    function getCustomerByCell(relWorkCellCode) {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getCustomerByCell";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                code: relWorkCellCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                console.log('myobj:', JSON.stringify(myobj))
                if (myobj.code == '0') {
                    $("#customerCode").val(myobj.customer);
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $("#customerCode").focus();
                    $("#customerCode").select();
                }
            }
        });
    }



    //9；PDA自带扫描回车事件-源库位
    $("#workCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#workCellCode").val(sm);
            getWorkCell(sm, "workCellCode", "1");
        }
    });

    //10；PDA自带扫描回车事件-调入库位
    $("#relWorkCellCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#relWorkCellCode").val(sm);
            getWorkCell(sm, "relWorkCellCode", "2");
        }
    });

    //11：选择客户
    function goSelectCustomer() {
        api.openWin({
            name: 'uwmSelectCustomer',
            url: 'uwmSelectCustomer.html',
            pageParam: {
                name: "uwmInterBankTransferRqfh_zfzjcxcc",
            }
        });
    }

    //客户选择后回调函数
    function setCustomer(id, code, name) {
        customerGid = id;
        customerCode = code;
        customerName = name;
        //$("#workCenterCode").attr("value",code+":"+name);
        document.getElementById('customerCode').value = code + ":" + name;
        $("#boxnum").focus();
        idSelector = "boxnum";
    }

    //客户扫描校验
    function getCustomer(code, inputId) {
        var serverUrl = localStorage.getItem('serverUrl');
        var un = localStorage.getItem('un');
        var url = serverUrl + "/app/getCustomer";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                customerCode: code,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);
                    customerGid = list[0].customerGid;
                    customerCode = list[0].customerCode + ":" + list[0].customerName;
                    customerName = list[0].customerName;
                    document.getElementById(inputId).value = customerCode;
                    $("#boxnum").focus();
                    idSelector = "boxnum";

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });

                    $("#customerCode").focus();
                    $("#customerCode").select();
                }
            }
        });
    }

    var isActive = false
    //保存按钮
    function save() {
        if (isActive) {
            api.toast({
                msg: '正在提交，请不要重复操作',
                duration: 3000
            });
            return;
        }
        const submitButton = document.getElementById('submitButton');

        submitButton.style.pointerEvents = "none"
        //发货单号
        var consignment = $("#consignment").val();
        //调入库位非空校验
        if (relWorkCellGid == "" || relWorkCellGid == null || relWorkCellGid == undefined) {
            api.toast({
                msg: '请选择/扫描 调入库位',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }

        //源仓库和目标仓库不能一样
        if (workCellGid != null && workCellGid != "" && workCellGid == relWorkCellGid) {
            api.toast({
                msg: '源库位和调入库位不能一样',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }


        if (arrSaveContainer.length == 0) {
            api.toast({
                msg: '没有需要保存的物料信息',
                duration: 3000
            });
            submitButton.style.pointerEvents = "auto"
            return;
        }

        var ctBarRedis = []
        var arrs = arrSaveContainer.split(",")
        arrs.forEach(item => {
            ctBarRedis.push(item);
        });
        api.showProgress({
            title: '保存中...',
        });
        isActive = true;
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/uwmContainerSaveCpfh";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                customerGid: customerGid, // 客户
                consignment: consignment, // 发货单号
                relWorkCellGid: relWorkCellGid, // 调入库位
                workCellGid: workCellGid, //源库位编码
                subBussinessType: codesub, //子业务类型
                list: JSON.stringify(arrSave),
                containerList: arrSaveContainer,//容器、箱信息
                un: un
                ,ctBarRedis:JSON.stringify(ctBarRedis)
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            isActive = false;
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                console.log("返回来啦:" + data);
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    arrSave = [];
                    tableStr = [];
                    num = 0
                    $("#num").val(0);
                    customerGid = '';
                    customerCode = '';
                    customerName = '';
                    arrSaveContainer = '';
                    $("#customerCode").val("");
                    $("#consignment").val("");
                    $("#tm").val("");
                    $("#tmID").val("");
                    $("#boxnum").val("");
                    $("#mrlCode").val("");
                    $("#lotCode").val("");
                    $("#qty").val("");
                    //回显保存结果
                    var list = myobj.list;
                    for (var i = 0; i < list.length; i++) {
                        var model = {
                            boxnum: list[i].boxnum, //
                            mrlCode: list[i].mrlCode, //
                            drawing: list[i].drawing,
                            lotCode: list[i].lotCode, //
                            qty: list[i].qty,
                            serialNum: list[i].serialNum,
                            typeFlag: list[i].typeFlag,
                            resultCode: list[i].resultCode, //
                            resultMsg: list[i].resultMsg,
                        }
                        var model2 = {
                            boxnum: list[i].boxnum, //
                            mrlCode: list[i].mrlCode, //
                            drawing: list[i].drawing,
                            lotCode: list[i].lotCode, //
                            qty: list[i].qty,
                            serialNum: list[i].serialNum,
                            typeFlag: list[i].typeFlag,
                            resultCode: list[i].resultCode, //
                            resultMsg: list[i].resultMsg,
                        }
                        arrSave.push(model);
                        tableStr.push(model2);
                    }
                    setTableAfter(arrSave);
                    $("#message").html(myobj.message);
                    $("#boxnum").focus();
                    idSelector = "boxnum";
                } else if (myobj.code == '1') {
                    $("#boxnum").val("");
                    api.hideProgress();
                    submitButton.style.pointerEvents = "auto"
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                submitButton.style.pointerEvents = "auto"
            }
        });
    }


    //扫描之后条码解析
    function tmSplit(sm) {
        //后台解析
        postAnalyze(sm);

    }


    function setTable(list) {
        var html = "";
        var arrSaveContainerNew = [];
        var arrSaveContainerStr = '';

        for (var i = 0; i < list.length; i++) {
            if (arrSaveContainerNew.indexOf(list[i].boxnum) == -1) {
                arrSaveContainerNew.push(list[i].boxnum);
                arrSaveContainerStr = arrSaveContainerStr + (arrSaveContainerStr == '' ? '' : ',') + list[i].boxnum;
            }
            html += "<li class='sortable ui-selectee ui-sortable'>";
            html += "<ul class='aui-list aui-media-list ui-selectee'>";

            html += "<li class='aui-list-item  ui-selectee' >";
            html += "<div class='aui-media-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>容器：</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].boxnum + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料号：</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].mrlCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>规格：</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].drawing + "</div>";
            html += "</div>";
            // html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            // html += "<div class='aui-list-item-label ui-selectee list-tr-title'>批次号：</div>";
            // html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].lotCode + "</div>";
            // html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量：</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].qty + "</div>";
            html += "</div>";
            // if(list[i].serialNum != undefined){
            //     html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            //     html += "<div class='aui-list-item-label ui-selectee list-tr-title'>序列号：</div>";
            //     html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].serialNum + "</div>";
            //     html += "</div>";
            // }
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作结果：</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + '' + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作信息：</div>";
            html += "<div class='aui-list-item-inner ui-selectee'>" + '' + "</div>";
            html += "<div class='aui-list-item-right aui-btn ui-selectee' style='background:red;color:#f5f5f5;' onclick='remove(\"" + list[i].boxnum + "\");'>移除</div>";
            html += "</div>";

            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        arrSaveContainer = arrSaveContainerStr;
        $api.html($api.byId("tbodyHtmlS"), html);
        setTable2(tableStr);
    };
    function remove(boxnum) {
        num = num - 1;
        arrSave = arrSave.filter(item => item.boxnum !== boxnum)
        tableStr = tableStr.filter(item => item.boxnum !== boxnum)
        $("#num").val(num);
        setTable(arrSave);
        setTable2(tableStr)

    };

    function setTable2(tableStr) {
        for (var i = 0; i < tableStr.length; i++) {
            var mrlCode = tableStr[i].mrlCode;
            for (var j = i + 1; j < tableStr.length; j++) {
                if (mrlCode == tableStr[j].mrlCode) {
                    tableStr[i].qty = Number(tableStr[i].qty) + Number(tableStr[j].qty);
                    tableStr.splice(j, 1);
                    j--;
                }

            }
        }
        var html = "";
        for (var i = 0; i < tableStr.length; i++) {
            html += "<tr style='text-align: center;color: black;font-size: 10px;background-color: #F5F5F5;'>";
            html += "<td name='mrlCode'>" + tableStr[i].mrlCode + "</td>";
            html += "<td name='drawing'>" + tableStr[i].drawing + "</td>";
            html += "<td name='qty'>" + tableStr[i].qty + "</td>";
            html += "</tr>";
        }
        $api.html($api.byId("tbodyHtml"), html);
        if (tableStr.length == 0) {
            $("#num").val(0);
        }

    };

    function setTableAfter(list) {
        var html = "";
        for (var i = 0; i < list.length; i++) {

            html += "<ul class='aui-list aui-media-list ui-selectee' >";
            if (list[i].resultCode === 'S') {
                console.log(111)
                html += "<li class='aui-list-item  ui-selectee' style='background:#98FB98';>";
            } else if (list[i].resultCode === 'E') {
                console.log(2222)
                html += "<li class='aui-list-item  ui-selectee' style='background:#FA8072';>";
            } else {
                console.log(333)
                html += "<li class='aui-list-item  ui-selectee'>";
            }
            html += "<div class='aui-media-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-inner ui-selectee'>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>容器：</div>";
            html += "<div class='aui-list-item-inner ui-selectee 'style='color:black'>" + list[i].boxnum + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>物料号：</div>";
            html += "<div class='aui-list-item-inner ui-selectee ' style='color:black'>" + list[i].mrlCode + "</div>";
            html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>规格：</div>";
            html += "<div class='aui-list-item-inner ui-selectee 'style='color:black'>" + list[i].drawing + "</div>";
            html += "</div>";
            // html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            // html += "<div class='aui-list-item-label ui-selectee list-tr-title'>批次号：</div>";
            // html += "<div class='aui-list-item-inner ui-selectee 'style='color:black'>" + list[i].lotCode + "</div>";
            // html += "</div>";
            html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            html += "<div class='aui-list-item-label ui-selectee list-tr-title'>数量：</div>";
            html += "<div class='aui-list-item-inner ui-selectee 'style='color:black'>" + list[i].qty + "</div>";
            html += "</div>";
            // if(list[i].typeFlag === "1"){
            //     html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
            //     html += "<div class='aui-list-item-label ui-selectee list-tr-title'>序列号：</div>";
            //     html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].serialNum + "</div>";
            //     html += "</div>";
            // }

            if (list[i].resultCode != null && list[i].resultCode != "" && list[i].resultCode != undefined) {
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作结果：</div>";
                html += "<div class='aui-list-item-inner ui-selectee 'style='color:black'>" + list[i].resultCode + "</div>";
                html += "</div>";
                if (list[i].resultCode === 'S') {
                    html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                    html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作信息：</div>";
                    html += "<div class='aui-list-item-inner ui-selectee 'style='color:black'>" + list[i].resultMsg + "</div>";
                    html += "</div>";
                } else {
                    html += "<div class='aui-list-item-text ui-selectee' style='height: 50px;'>";
                    html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作信息：</div>";
                    html += "<div class='aui-list-item-inner ui-selectee 'style='color:black'>" + list[i].resultMsg + "</div>";
                    html += "</div>";
                }


            } else {
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作结果：</div>";
                html += "<div class='aui-list-item-inner ui-selectee'>" + '' + "</div>";
                html += "</div>";
                html += "<div class='aui-list-item-text ui-selectee' style='height: 15px;'>";
                html += "<div class='aui-list-item-label ui-selectee list-tr-title'>操作信息：</div>";
                html += "<div class='aui-list-item-inner ui-selectee'>" + '' + "</div>";
                html += "</div>";
            }


            html += "</div>";
            html += "</li>";
            html += "</ul>";
            html += "</li>";
        }
        $api.html($api.byId("tbodyHtmlS"), html);
        setTable2(tableStr);
        arrSave = [];
        tableStr = [];
        $("#num").val(0);
    };
    //校验
    function checkout(tm, mrlCode, lotCode, qty, boxnum, tmID, drawing, type, serialNum) {
        if (customerGid == "" || customerGid == null || customerGid == undefined) {
            var model = {
                mrlCode: mrlCode, //物料号
                drawing: drawing, //规格
                lotCode: lotCode, //批次号
                qty: qty, //转移数量
                tm: tm, //条码
                boxnum: boxnum, //容器
                tmID: tmID, //条码ID
                serialNum: serialNum,
                typeFlag: type
            }
            var model2 = {
                mrlCode: mrlCode, //物料号
                drawing: drawing, //规格
                lotCode: lotCode, //批次号
                qty: qty, //转移数量
                tm: tm, //条码
                boxnum: boxnum, //容器
                tmID: tmID, //条码ID
                serialNum: serialNum,
                typeFlag: type
            }
            arrSave.push(model);
            tableStr.push(model2);
            console.log("回显保存结果list111111:" + JSON.stringify(arrSave));
            $("#boxnum").val("");
            $("#boxnum").select();
            idSelector = "boxnum";
            setTable(arrSave);

        } else {
            var customerCode = $("#customerCode").val();//客户编码
            var serverUrl = localStorage.getItem('serverUrl');
            var un = localStorage.getItem("un");
            var url = serverUrl + "/app/getCheckOut";
            var data = {
                values: {
                    un: un,
                    mrlCode: mrlCode,
                    customerCode: customerCode
                }
            };
            api.ajax({
                url: url,
                method: 'post',
                dataType: 'json',
                timeout: 300,
                returnAll: false,
                data: data
            }, function (ret, err) {
                if (ret) {
                    var data = JSON.stringify(ret);
                    var myobj = eval("(" + data + ")");
                    //成功
                    console.log(myobj.code);
                    if (myobj.code == '0') {

                        var model = {
                            mrlCode: mrlCode, //物料号
                            drawing: drawing,
                            lotCode: lotCode, //批次号
                            qty: qty, //转移数量
                            tm: tm, //条码
                            boxnum: boxnum, //容器
                            tmID: tmID, //条码ID
                            serialNum: serialNum,
                            typeFlag: type
                        }
                        var model2 = {
                            mrlCode: mrlCode, //物料号
                            drawing: drawing,
                            lotCode: lotCode, //批次号
                            qty: qty, //转移数量
                            tm: tm, //条码
                            boxnum: boxnum, //容器
                            tmID: tmID, //条码ID
                            serialNum: serialNum,
                            typeFlag: type
                        }
                        arrSave.push(model);
                        tableStr.push(model2);
                        console.log("回显保存结果list111111:" + JSON.stringify(arrSave));
                        $("#boxnum").val("");
                        $("#boxnum").select();
                        idSelector = "boxnum";
                        setTable(arrSave)

                    } else if (myobj.code == '1') {

                        $("#boxnum").val("");
                        $("#boxnum").select();
                        idSelector = "boxnum";
                        api.toast({
                            msg: myobj.message,
                            duration: 3000
                        });
                    }
                } else {
                    $("#boxnum").val("");
                    $("#boxnum").select();
                    idSelector = "boxnum";
                    api.hideProgress();
                    alert(JSON.stringify(err));

                }
            });
        }


    }

    //后台解析条码
    function postAnalyze(sm) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getBoxInfoByContainerCPFH";
        var data = {
            values: {
                container: sm, //条码
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                for (var i = 0; i < arrSave.length; i++) {
                    if (sm == arrSave[i].boxnum) {
                        api.toast({
                            msg: '容器已扫描,请检查！',
                            duration: 3000
                        });

                        return;
                    }
                }

                //成功
                if (myobj.code == '0') {
                    var map = myobj.list;
                    $("#boxnum").val("");
                    //判断容器是否重复
                    for (var i = 0; i < arrSave.length; i++) {
                        if (myobj.tmID == arrSave[i].tmID) {
                            api.toast({
                                msg: '容器已存在！',
                                duration: 3000
                            });

                            return;
                        }
                    }
                    num = num + 1;
                    $("#num").val(num);
                    console.log(JSON.stringify(myobj));
                    if (myobj.type === '1') {
                        for (var p in map) {
                            checkout(map[p].ctBarcode, map[p].mrlCode, map[p].ext05, map[p].qty, map[p].ctBarcode, myobj.tmID, map[p].drawing, myobj.type, map[p].serialNum);
                        }
                        workCellGid = myobj.wellId;
                        $("#workCellCode").val(myobj.wellCode + ":" + myobj.wellName);

                    } else if (myobj.type === '0') {
                        for (var p in map) {
                            checkout(map[p].tm, map[p].sitmCode, map[p].lotCode, map[p].qyt, map[p].boxnum, map[p].tmid, myobj.drawing, myobj.type)
                        }

                        workCellGid = myobj.wellId;
                        $("#workCellCode").val(myobj.wellCode + ":" + myobj.wellName);
                    }
                    setTable(arrSave);
                } else if (myobj.code == '1') {

                    $("#boxnum").val("");
                    $("#boxnum").select();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert(JSON.stringify(err));
            }
        });
    }


    //容器监听回车事件
    $("#boxnum").on('keypress', function (e) { //#keyword为input文本框
        if (!clickThrottle()) {
            $("#boxnum").val("");
            return;
        }
        var keycode = e.keyCode;
        var tm = $(this).val();
        $("#boxnum").val("");
        if (keycode == '13') {
            //$("#boxnum").select();
            $("#boxnum").blur();
            //调用条码解析+保存事件
            console.log("tm11:" + tm);
            // $("#boxnum").blur();
            console.log("tm22:" + tm);
            //扫描之后条码解析
            tmSplit(tm);
        }
    });
    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
    function focusFn(ele) {
        $api.attr(ele, 'readonly', 'readonly');
        setTimeout(function () {
            $api.removeAttr(ele, 'readonly');
        }, 200);
    };
</script>

</html>